/* 
 * File:   EngineFacadeThread.cpp
 * Author: ariel
 * 
 * Created on 4 de diciembre de 2009, 19:55
 */

#include "EngineFacadeThread.h"


void EngineFacadeThread::run() {
    std::string command;
    std::string response;
    try {
        (*socket)>>command;
        Method method = parseCommand(command);
        response=(engine->*method)(command);
        (*socket)<<response;
    } catch(std::exception& exc) {
        // Ver si no tiro otras excepciones...
        (*socket)<<std::string(exc.what());
    } catch(...) {
        (*socket)<<std::string("cannot execute command");
    }

}

Method EngineFacadeThread::parseCommand(std::string& command) throw(std::exception) {
    std::vector<std::string> parsed;
    parsed = StaticUtils::split(command,std::string("."));
    command.erase(0,parsed[0].size()+1);
    return engine->getCommand(parsed[0]);
}

EngineFacadeThread::~EngineFacadeThread() {
    this->engine=NULL;
    delete(socket);
    socket=NULL;
}

